package com.poor.user.service.web;
import com.poor.user.service.core.Result;
import com.poor.user.service.core.ResultGenerator;
import com.poor.user.service.model.PoorIntegral;
import com.poor.user.service.service.PoorIntegralService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by lcy on 2019/01/22.
*/
@RestController
@RequestMapping("/poor/integral")
public class PoorIntegralController {
    @Resource
    private PoorIntegralService poorIntegralService;

    @PostMapping("/add")
    public Result add(PoorIntegral poorIntegral) {
        poorIntegralService.save(poorIntegral);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        poorIntegralService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(PoorIntegral poorIntegral) {
        poorIntegralService.update(poorIntegral);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        PoorIntegral poorIntegral = poorIntegralService.findById(id);
        return ResultGenerator.genSuccessResult(poorIntegral);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<PoorIntegral> list = poorIntegralService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
